import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn,  } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";

export enum SkillType {
  WARRIOR = 1, // 武士技能
  SCHOLAR = 2, // 文人技能
  MAGE = 3, // 异师技能
  SPECIAL = 0, // 特殊技能
}

export enum SkillSide {
  OFFENSIVE = 1, // 攻击技能
  DEFENSIVE = 2, // 防御技能
}

@Entity("character_skills")
@ManualTimestamp()
export class CharacterSkillEntity {
  @PrimaryGeneratedColumn()
  id!: number;

  @Column("int", { comment: "角色ID" })
  characterId!: number;

  @Column("int", { comment: "技能ID" })
  skillId!: number;

  @Column("int", { comment: "技能等级", default: 0 })
  grade!: number;

  @Column("int", { comment: "技能花数", default: 0 })
  hua!: number;

  @Column("int", { comment: "使用次数", default: 0 })
  useCount!: number;

  @Column("int", { comment: "技能类型：1-武士，2-文人，3-异师，0-特殊" })
  skillType!: SkillType;

  @Column("varchar", { length: 50, comment: "技能名称" })
  skillName!: string;

  @Column("int", { comment: "技能方向：1-攻击，2-防御" })
  skillSide!: SkillSide;

  @Column("varchar", { length: 10, comment: "技能简称" })
  skillShort!: string;

  @Column("varchar", { length: 50, comment: "技能动画" })
  skillAni!: string;

  @Column("int", { comment: "技能状态：0-未激活，1-已激活", default: 0 })
  status!: number;

  @Column("datetime", {
    comment: "获得时间",
  })
  obtainedAt!: Date;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", {
    name: "updated_at",
    comment: "更新时间",
    nullable: true,
  })
  updated_at!: Date | null;

  // 关联关系
  @ManyToOne(() => CharacterEntity, (character) => character.skills)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;
}
